/*
 * BanBu_SpecialTextCell
 * @description 本文件提供聊天界面对话界面显示网页型消息的cell
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供聊天界面对话界面显示网页型消息的cell
 */
//复文本消息：广播通知、动态通知、推荐好友、推荐游戏、推荐应用、第三方插件消息、网址

#import "BanBu_SpecialTextCell.h"
#import "BanBuAPIs.h"
#import "AppDataManager.h"
#import "BanBu_ChatViewController.h"

@implementation BanBu_SpecialTextCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        //网页
        _specialView = [[BanBu_SpecialText alloc]initWithFrame:CGRectZero];
        _specialView.backgroundColor = [UIColor clearColor];
        [self addSubview:_specialView];
        
        _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        [_activityIndicator setFrame:CGRectMake(0, 17, 30, 30)];
        _activityIndicator.center = self.bkView.center;
        [_activityIndicator setHidesWhenStopped:YES];
        [_activityIndicator setColor:[UIColor blackColor]];
        
        [_activityIndicator  startAnimating];
        [self addSubview:_activityIndicator];
    }
    return self;
}

-(void)dealloc
{
    [_activityIndicator release],_activityIndicator = nil;
    [_specialView release],_specialView = nil;
    
    [super dealloc];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.bkView.alpha = 1;
    _specialView.frame = SpecialViewRext00;
    _specialView.cell = self;
    [_specialView setWebViewFrame:_specialView.frame];
    self.activityIndicator.center = self.bkView.center;
    
    [self setMsgMediastatus:self.mediastatus];
    
//    if (self.bubbleID == 0)
    {
        CGRect frame = _specialView.frame;
        frame.origin.y += 4;
        if (!self.atLeft)
        {
            frame.origin.x += 3;
        }
        _specialView.frame = frame;
        _specialView.webView.layer.cornerRadius = 12;
    }
    
    self.avatar.frame = AvatarRect01;
//    [self.vipImageView setFrame:CGRectMake(self.avatar.frame.origin.x + 28, self.avatar.frame.origin.y + 26, 15, 10)];
}

-(void)setMsgMediastatus:(MediaStatus)status
{
    if(status != MediaStatusNormal && status != MediaStatusReaded)//不是：已播过或正常时，loading转圈
    {
        [self.activityIndicator  startAnimating];
    }
    else
    {
        if (self.type == ChatCellTypeSpecialText)
        {
            _specialView.chat = _chat;
            _specialView.cell = self;
            _specialView.showTime = self.showTime;
            
            if (self.height<= 57 && self.showTime == NO)//特殊类型的高度不对
            {
                _specialView.webView.delegate = self.specialView;
                _specialView.set = YES;
                _specialView.amsg = [NSDictionary dictionaryWithObjectsAndKeys:self.chatid,KeyChatid,MyAppDataManager.chatuid,KeyFromUid, nil];
                _specialView.alpha = 0;
                self.bkView.hidden = YES;
                [self.activityIndicator  startAnimating];
            }
            else if (self.height-TimeLabelHeight<= 57 && self.showTime == YES)
            {
                self.specialView.webView.delegate = self.specialView;
                self.specialView.set = YES;
                self.specialView.amsg = [NSDictionary dictionaryWithObjectsAndKeys:self.chatid,KeyChatid,MyAppDataManager.chatuid,KeyFromUid, nil];
                self.specialView.alpha = 0;
                self.bkView.hidden = YES;
                [self.activityIndicator  startAnimating];
            }
            else
            {
                self.specialView.webView.delegate = nil;
                self.specialView.set = NO;
                self.specialView.amsg = nil;
                self.specialView.alpha = 1;
                self.bkView.hidden = NO;
                [self.activityIndicator  stopAnimating];
            }
        }
        else
        {
            [self.activityIndicator  stopAnimating];
        }
    }
}

//设置cell的各种信息
-(void)setChatCellInfo:(NSDictionary *)amsg
{
    self.bkViewWidth = 200.0;
    [super setChatCellInfo:amsg];
    
    self.showFrom  = NO;
    [_specialView setContent:[amsg valueForKey:KeyContent]];
    [_specialView setLinkTo:[amsg valueForKey:KeyLinkTo]];
}
@end
